// pages/24ssys/24ssys.js
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		season: "",
		current: 0,
		title: "",
		foodItems:[],
		menuItems:[],
		tabooItems:[]
	},
	handleNav(ev) {
		this.setData({
			current: ev.currentTarget.dataset.id
		})
	},
	handlechange(ev) {
		this.setData({
			current: ev.detail.current
		})
	},
	goBackmyPage() {
		wx.navigateBack({
			delta: 1
		})
	},
	gotoMenu() {
		wx.navigateTo({
			url: '../menu/menu',
		})
	},
	// gotoFood() {
	// 	wx.navigateTo({
	// 		url: '../food/food',
	// 	})
	// },

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {

		//获取系统信息
		wx.getSystemInfo({
			success: res => {
				this.system = res
			}
		})

		//获取胶囊信息
		this.menu = wx.getMenuButtonBoundingClientRect()
		this.systemBar = this.system.statusBarHeight //状态栏高度
		this.navigationBar = (this.menu.top - this.system.statusBarHeight) * 2 + this.menu.height //胶囊高度
		this.sumBar = this.systemBar + this.navigationBar
		// console.log(this.menu)
		// console.log(this.systemBar)
		// console.log(this.navigationBar)
		this.setData({
			systemBar: this.systemBar,
			navigationBar: this.navigationBar,
			sumBar: this.sumBar,
			season: options.season,
			title:options.title,
			mainHeight:wx.getSystemInfoSync().windowHeight - this.sumBar
		})
		this.getTitle();
		this.getFoodItems();
		this.getMenuItems();
		this.getTabooItems();
	},
	getTitle() {
		switch (this.data.season) {
			case "lc":
				this.setData({
					title: "立春"
				});
				break;
			case "ys":
				this.setData({
					title: "雨水"
				});
				break;
			case "jz":
				this.setData({
					title: "惊蛰"
				});
				break;
				case "cf":
					this.setData({
						title: "春分"
					});
					break;
			case "qm":
				this.setData({
					title: "清明"
				});
				break;
			case "gy":
				this.setData({
					title: "谷雨"
				});
				break;
			case "lx":
				this.setData({
					title: "立夏"
				});
				break;
			case "xm":
				this.setData({
					title: "小满"
				});
				break;
			case "mz":
				this.setData({
					title: "芒种"
				});
				break;
			case "xz":
				this.setData({
					title: "夏至"
				});
				break;
			case "xs":
				this.setData({
					title: "小暑"
				});
				break;
			case "ds":
				this.setData({
					title: "大暑"
				});
				break;
			case "lq":
				this.setData({
					title: "立秋"
				});
				break;
			case "cs":
				this.setData({
					title: "处暑"
				});
				break;
			case "bl":
				this.setData({
					title: "白露"
				});
				break;
			case "qf":
				this.setData({
					title: "秋分"
				});
				break;
			case "hs":
				this.setData({
					title: "寒霜"
				});
				break;
			case "sj":
				this.setData({
					title: "霜降"
				});
				break;
			case "ld":
				this.setData({
					title: "立冬"
				});
				break;
			case "xx":
				this.setData({
					title: "小雪"
				});
				break;
			case "dx":
				this.setData({
					title: "大雪"
				});
				break;
			case "dz":
				this.setData({
					title: "冬至"
				});
				break;
			case "xh":
				this.setData({
					title: "小寒"
				});
				break;
			case "dh":
				this.setData({
					title: "大寒"
				});
				break;
		}
	},

	getFoodItems(){

		// var app = getApp();
		// var api = 'https://'+app.globalData.env+'.'+ app.globalData.region +'.kits.tcloudbasegateway.com/cms/'+ app.globalData.kitId +'4a9s0behzkfeao9x/v1/open-api/projects/'+ app.globalData.projectId +'/collections/scjm/contents?limit=10&offset=0'

		var that = this;
		wx.request({
			url: 'https://cloud1-3g39lqq2cbc35cd7.ap-shanghai.kits.tcloudbasegateway.com/cms/4a9s0behzkfeao9x/v1/open-api/projects/24meals/collections/scjm/contents?limit=100&offset=0',
			header: {
				'content-type': 'application/json'
			},
			success (res1) {
				// console.log('cms数据',res1)
				that.setData(
					{
						foodItems:res1.data.result.data
					}
				)
			}
		})
	},

	getMenuItems(){
		var that = this;
		wx.request({
			url: 'https://cloud1-3g39lqq2cbc35cd7.ap-shanghai.kits.tcloudbasegateway.com/cms/4a9s0behzkfeao9x/v1/open-api/projects/24meals/collections/slcp/contents?limit=100&offset=0',
			header: {
				'content-type': 'application/json'
			},
			success (res2) {
				// console.log('cms数据',res2)
				that.setData(
					{
						menuItems:res2.data.result.data
					}
				)
			}
		})
	},
	getTabooItems(){
		var that = this;
		wx.request({
			url: 'https://cloud1-3g39lqq2cbc35cd7.ap-shanghai.kits.tcloudbasegateway.com/cms/4a9s0behzkfeao9x/v1/open-api/projects/24meals/collections/jppic/contents?limit=100&offset=0',
			header: {
				'content-type': 'application/json'
			},
			success (res3) {
				// console.log('cms数据3',res3)
				that.setData(
					{
						tabooItems:res3.data.result.data
					}
				)
			}
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})